const path = require('path')

const resolve = dir => path.join(__dirname, dir)
const publicPath = '/'
const outputDir = 'dist'

module.exports = {
  runtimeCompiler: true,
  devServer: {
    port: 8081,
    overlay: {
      warnings: true,
      errors: true
    }
  },
  publicPath: publicPath,
  outputDir: outputDir,
  lintOnSave: true,
  chainWebpack: config => {
    config.resolve.alias
      .set('@', resolve('src'))
      .end()
    config.module
      .rule('raw-loader')
      .test(/.(bpmn|xml)$/)
      .use('raw-loader')
      .loader('raw-loader')
      .end()
    config.when(process.env.NODE_ENV !== 'development', config => {
      config.optimization.splitChunks({
        chunks: 'all',
        cacheGroups: {
          libs: {
            name: 'chunk-libs',
            test: /[\\/]node_modules[\\/]/,
            priority: 10,
            chunks: 'initial'
          },
          elementUI: {
            name: 'chunk-elementUI',
            priority: 20,
            test: /[\\/]node_modules[\\/]_?element-ui(.*)/
          },
          commons: {
            name: 'chunk-commons',
            test: resolve('src/components'),
            minChunks: 3,
            priority: 5,
            reuseExistingChunk: true
          }
        }
      })
      config.optimization.runtimeChunk('single')
    })
  },
  productionSourceMap: false
}
